{{- define "api" -}}
<section class="api">
    <h3>
        <span class="method {{.Method}}">{{.Method}}</span>
        <span class="url">{{.URL}}</span>
        <span class="summary">{{.Summary}}</span>
    </h3>

    <div class="content">
        {{if .Description}}
        <p class="description">{{.Description}}</p>
        {{end}}

        {{if .Queries}}
            <h5>查询参数</h5>
            {{template "params" .Queries}}
        {{end}}

        {{if .Params}}
            <h5>参数</h5>
            {{template "params" .Params}}
        {{end}}

        {{if .Request}}
        <div class="request">
            <h4>请求{{if .Request.Type}}:&#160;{{.Request.Type}}{{end}}</h4>
            <div>
                {{if .Request.Headers}}
                    <h5>报头:</h5>
                    {{template "headers" .Request.Headers}}
                {{end}}

                {{if .Request.Params}}
                    <h5>参数:</h5>
                    {{template "params" .Request.Params}}
                {{end}}

                {{if .Request.Examples}}
                    <h5>示例:</h5>
                    {{template "examples" .Request.Examples}}
                {{end}}
            </div>
        </div>
        {{end}}

        {{if .Success}}
        <div class="response success">
            <h4><span class="success">SUCCESS:</span>{{.Success.Code}},&#160;{{.Success.Summary}}</h4>
            {{template "response" .Success}}
        </div>
        {{end}}

        {{if .Error}}
        <div class="response error">
            <h4><span class="error">ERROR:</span>{{.Error.Code}},&#160;{{.Error.Summary}}</h4>
            {{template "response" .Error}}
        </div>
        {{end}}
    </div>
</section>
{{- end -}}



{{- define "examples" -}}
{{range .}}
<pre><code class="language-{{.Type|lower}}">{{- .Code -}}
</code></pre>
{{end}}
{{- end -}}



{{/* @apiParam 和 @apiQuery */}}
{{- define "params" -}}
<table class="params">
    <thead>
        <tr><th>名称</th><th>类型</th><th>描述</th></tr>
    </thead>
    <tbody>
    {{range . -}}
    <tr>
        <th>{{.Name}}</th>
        <td>{{.Type}}</td>
        <td>{{.Summary}}</td>
    </tr>
    {{- end}}
    </tbody>
</table>
{{- end -}}


{{/* @apiHeader */}}
{{- define "headers" -}}
<table>
    <thead>
        <tr><th>名称</th><th>描述</th></tr>
    </thead>
    <tbody>
    {{range $k, $v := . -}}
    <tr>
        <th>{{$k}}</th>
        <td>{{$v}}</td>
    </tr>
    {{- end}}
    </tbody>
</table>
{{- end -}}



{{/* @apiSuccess 和 @apiError */}}
{{- define "response" -}}
        {{if .Headers -}}
            <h5>请求头</h5>
            {{template "headers" .Headers}}
        {{- end}}

        {{- if .Params -}}
            <h5>参数:</h5>
            {{template "params" .Params}}
        {{- end}}

        {{- if .Examples -}}
            <h5>示例:</h5>
            {{template "examples" .Examples}}
        {{- end}}
{{- end -}}
